3a03ce0cf36cf94019f72c2e038d8945e1ee93a3,OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java,ConfigureMapMenu,createRenderingAttributeItems,#ContextMenuAdapter#MapActivity#,271
Before Change
}).createItem());
RenderingRulesStorage renderer = activity.getMyApplication().getRendererRegistry().getCurrentSelectedRenderer();
if (renderer != null) {
List<RenderingRuleProperty> customRules = new ArrayList<>();
for (RenderingRuleProperty p : renderer.PROPS.getCustomRules()) {
if (!RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN.equals(p.getCategory())) {
customRules.add(p);
}
}
createProperties(customRules, R.string.rendering_category_transport,
R.drawable.ic_action_bus_dark, "transport", adapter, activity);
createProperties(customRules, R.string.rendering_category_details,
R.drawable.ic_action_layers_dark, "details", adapter, activity);
createProperties(customRules, R.string.rendering_category_hide,
R.drawable.ic_action_hide, "hide", adapter, activity);
createProperties(customRules, R.string.rendering_category_routes,
R.drawable.ic_action_map_routes, "routes", adapter, activity);
After Change
activity.getMapView().refreshMap(true);
}
private void createRenderingAttributeItems(List<RenderingRuleProperty> customRules,
final ContextMenuAdapter adapter, final MapActivity activity) {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_map_rendering, activity)
.setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_renderer, activity)
.setDescription(getRenderDescr(activity)).setLayout(R.layout.list_item_single_line_descrition_narrow)
.setIcon(R.drawable.ic_map).setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId,
final int pos, boolean isChecked) {
AlertDialog.Builder bld = new AlertDialog.Builder(activity);
bld.setTitle(R.string.renderers);
final OsmandApplication app = activity.getMyApplication();
Collection<String> rendererNames = app.getRendererRegistry().getRendererNames();
final String[] items = rendererNames.toArray(new String[rendererNames.size()]);
final String[] visibleNames = new String[items.length];
int selected = -1;
final String selectedName = app.getRendererRegistry().getCurrentSelectedRenderer().getName();
for (int j = 0; j < items.length; j++) {
if (items[j].equals(selectedName)) {
selected = j;
}
visibleNames[j] = items[j].replace('_', ' ').replace('-', ' ');
}
bld.setSingleChoiceItems(visibleNames, selected, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String renderer = items[which];
RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(renderer);
if (loaded != null) {
OsmandMapTileView view = activity.getMapView();
view.getSettings().RENDERER.set(renderer);
app.getRendererRegistry().setCurrentSelectedRender(loaded);
refreshMapComplete(activity);
} else {
Toast.makeText(app, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
}
adapter.getItem(pos).setDescription(getRenderDescr(activity));
activity.getDashboard().refreshContent(true);
dialog.dismiss();
}
});
bld.show();
return false;
}
}).createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_mode, activity)
.setDescription(getDayNightDescr(activity)).setLayout(R.layout.list_item_single_line_descrition_narrow)
.setIcon(getDayNightIcon(activity)).setListener(new ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId,
final int pos, boolean isChecked) {
final OsmandMapTileView view = activity.getMapView();
AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
bld.setTitle(R.string.daynight);
final String[] items = new String[OsmandSettings.DayNightMode.values().length];
for (int i = 0; i < items.length; i++) {
items[i] = OsmandSettings.DayNightMode.values()[i].toHumanString(activity
.getMyApplication());
}
int i = view.getSettings().DAYNIGHT_MODE.get().ordinal();
bld.setSingleChoiceItems(items, i, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
view.getSettings().DAYNIGHT_MODE.set(OsmandSettings.DayNightMode.values()[which]);
refreshMapComplete(activity);
dialog.dismiss();
activity.getDashboard().refreshContent(true);
// adapter.getItem(pos).setDescription(s, getDayNightDescr(activity));
// ad.notifyDataSetInvalidated();
}
});
bld.show();
return false;
}
}).createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.map_magnifier, activity)
.setDescription(
String.format(Locale.UK, "%.0f",
100f * activity.getMyApplication().getSettings().MAP_DENSITY.get())
+ " %").setLayout(R.layout.list_item_single_line_descrition_narrow)
.setIcon(R.drawable.ic_action_map_magnifier).setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId,
final int pos, boolean isChecked) {
final OsmandMapTileView view = activity.getMapView();
final OsmandSettings.OsmandPreference<Float> mapDensity = view.getSettings().MAP_DENSITY;
final AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
int p = (int) (mapDensity.get() * 100);
final TIntArrayList tlist = new TIntArrayList(new int[] { 33, 50, 75, 100, 150, 200, 300, 400 });
final List<String> values = new ArrayList<>();
int i = -1;
for (int k = 0; k <= tlist.size(); k++) {
final boolean end = k == tlist.size();
if (i == -1) {
if ((end || p < tlist.get(k))) {
values.add(p + " %");
i = k;
} else if (p == tlist.get(k)) {
i = k;
}
}
if (k < tlist.size()) {
values.add(tlist.get(k) + " %");
}
}
if (values.size() != tlist.size()) {
tlist.insert(i, p);
}
bld.setTitle(R.string.map_magnifier);
bld.setSingleChoiceItems(values.toArray(new String[values.size()]), i,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int p = tlist.get(which);
mapDensity.set(p / 100.0f);
view.setComplexZoom(view.getZoom(), view.getSettingsMapDensity());
MapRendererContext mapContext = NativeCoreContext.getMapRendererContext();
if (mapContext != null) {
mapContext.updateMapSettings();
}
adapter.getItem(pos).setDescription(
String.format(Locale.UK, "%.0f", 100f * activity.getMyApplication()
.getSettings().MAP_DENSITY.get())
+ " %");
ad.notifyDataSetInvalidated();
dialog.dismiss();
}
});
bld.show();
return false;
}
}).createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.text_size, activity)
.setDescription(getScale(activity)).setLayout(R.layout.list_item_single_line_descrition_narrow)
.setIcon(R.drawable.ic_action_map_text_size).setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId,
final int pos, boolean isChecked) {
final OsmandMapTileView view = activity.getMapView();
AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
// test old descr as title
b.setTitle(R.string.text_size);
final Float[] txtValues = new Float[] { 0.75f, 1f, 1.25f, 1.5f, 2f, 3f };
int selected = -1;
final String[] txtNames = new String[txtValues.length];
for (int i = 0; i < txtNames.length; i++) {
txtNames[i] = (int) (txtValues[i] * 100) + " %";
if (Math.abs(view.getSettings().TEXT_SCALE.get() - txtValues[i]) < 0.1f) {
selected = i;
}
}
b.setSingleChoiceItems(txtNames, selected, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
view.getSettings().TEXT_SCALE.set(txtValues[which]);
refreshMapComplete(activity);
adapter.getItem(pos).setDescription(getScale(activity));
ad.notifyDataSetInvalidated();
dialog.dismiss();
}
});
b.show();
return false;
}
}).createItem());
String localeDescr = activity.getMyApplication().getSettings().MAP_PREFERRED_LOCALE.get();
localeDescr = localeDescr == null || localeDescr.equals("") ? activity.getString(R.string.local_map_names)
: localeDescr;
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_locale, activity)
.setDescription(localeDescr).setLayout(R.layout.list_item_single_line_descrition_narrow)
.setIcon(R.drawable.ic_action_map_language).setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId,
final int pos, boolean isChecked) {
final OsmandMapTileView view = activity.getMapView();
AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
// test old descr as title
b.setTitle(R.string.map_preferred_locale);
final String[] txtIds = getSortedMapNamesIds(activity, mapNamesIds,
getMapNamesValues(activity, mapNamesIds));
final String[] txtValues = getMapNamesValues(activity, txtIds);
int selected = -1;
for (int i = 0; i < txtIds.length; i++) {
if (view.getSettings().MAP_PREFERRED_LOCALE.get().equals(txtIds[i])) {
selected = i;
break;
}
}
b.setSingleChoiceItems(txtValues, selected, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
view.getSettings().MAP_PREFERRED_LOCALE.set(txtIds[which]);
refreshMapComplete(activity);
String localeDescr = txtIds[which];
localeDescr = localeDescr == null || localeDescr.equals("") ? activity
.getString(R.string.local_map_names) : localeDescr;
adapter.getItem(pos).setDescription(localeDescr);
ad.notifyDataSetInvalidated();
dialog.dismiss();
}
});
b.show();
return false;
}
}).createItem());
ContextMenuItem props;
props = createProperties(customRules, R.string.rendering_category_transport, R.drawable.ic_action_bus_dark,
"transport", adapter, activity, true);
if(props != null) {
adapter.addItem(props);
}
props = createProperties(customRules, R.string.rendering_category_details, R.drawable.ic_action_layers_dark,
"details", adapter, activity, true);
if(props != null) {
adapter.addItem(props);
}
props = createProperties(customRules, R.string.rendering_category_hide, R.drawable.ic_action_hide, "hide",
adapter, activity, true);
if(props != null) {
adapter.addItem(props);
}
props = createProperties(customRules, R.string.rendering_category_routes, R.drawable.ic_action_map_routes,
"routes", adapter, activity, true);